package org.springblade.modules.repair.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springblade.core.tool.utils.Func;

/**
 * @Author ysq
 * @Date 2024/12/23
 * @Description sku信息工具类
 */
public class SkuInfoUtil {

	/**
	 * 组装sku属性
	 */
	public static String attrHandle(String brand, String spu, String attr) {
		StringBuilder sb = new StringBuilder();
		if (Func.isNotBlank(brand)) {
			sb.append(brand).append("/");
		}
		sb.append(spu).append("/");
		if (Func.isBlank(attr)) {
			return sb.toString();
		}
		JSONArray attrJsonArray = JSONArray.parseArray(attr);
		for (Object o : attrJsonArray) {
			JSONObject jsonObject = (JSONObject) o;
			if (jsonObject.getString("value") != null) {
				sb.append(jsonObject.getString("value"));
			}
			if (jsonObject.getString("unit") != null) {
				sb.append(jsonObject.getString("unit"));
			}
		}
		return sb.toString();
	}
}
